package com.tax.infrastructure.extension;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Map;

/**
 * duandehui
 * ExtensionBootstrap
 */
@Component
public class ExtensionBootstrap implements ApplicationContextAware {

    @Autowired
    private ExtensionRegister extensionRegister;

    private static ApplicationContext applicationContext;

    @PostConstruct
    public void init(){
        Map<String, Object> extensionBeans = applicationContext.getBeansWithAnnotation(Extension.class);
        extensionBeans.values().forEach(extension->{
            extensionRegister.doRegistration((ExtensionPointI) extension);
        });
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        ExtensionBootstrap.applicationContext=applicationContext;
    }
}
